Skip to content

Tests: Remove redundant trailing post type cleanup in Tests_AdminBar - #16267

Open
shail-mehta wants to merge 1 commit into
WordPress:trunkfrom
shail-mehta:tests/66755-remove-redundant-post-type-cleanup-admin-bar
Open

shail-mehta wants to merge 1 commit into
WordPress:trunkfrom
shail-mehta:tests/66755-remove-redundant-post-type-cleanup-admin-bar

Conversation

@shail-mehta

@shail-mehta shail-mehta commented Nov 26, 2026 •

Copy link
Copy Markdown
Member

Trac ticket: #66755

What

Removes 3 trailing unregister_post_type( 'foo-non-public' ) calls from the tests in Tests_AdminBar (tests/phpunit/tests/adminbar.php):

  • test_admin_bar_has_no_archives_link_for_non_public_cpt()
  • test_admin_bar_has_no_archives_link_for_cpt_without_archive()
  • test_admin_bar_has_no_archives_link_for_cpt_not_shown_in_admin_bar()

Why

foo-non-public is registered inside each test body, not in class-level setup, and is used only in tests/phpunit/tests/adminbar.php. So no later class's wpSetUpBeforeClass() depends on it.

WP_UnitTestCase_Base::set_up() already resets ordinary post types before every core test via reset_post_types() (tests/phpunit/includes/abstract-testcase.php). So the next test starts without foo-non-public registered, and the trailing calls add nothing for later tests.

How

Delete the three trailing unregister_post_type( 'foo-non-public' ) calls and the blank line after each.

Testing Instructions

Run the class in default and reverse order:

npm run test:php -- --filter Tests_AdminBar
npm run test:php -- --order-by=reverse --filter Tests_AdminBar

Local results (npm run test:php in the Docker environment, PHPUnit 9.6.39, single site):

  • Default order, class: OK (51 tests, 157 assertions)
  • Reverse order, class: OK (51 tests, 157 assertions)

Use of AI Tools

  • Cursor

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

No active review issues are reported for the removal of redundant post type cleanup from the admin bar tests.

No open issues 🎉

What changed in this PR

Simplifies Tests_AdminBar by removing explicit post type cleanup that is handled by the core test framework before each test.

Changes:

  • Removes three unregister_post_type( 'foo-non-public' ) calls and adjacent blank lines from archive-link tests.
  • Leaves post type registration and assertions unchanged.
File Description
tests/​phpunit/​tests/​adminbar.php Removes redundant cleanup from three custom post type archive-link tests.

Review effort: Balanced

@shail-mehta shail-mehta self-assigned this Nov 26, 2026
@shail-mehta
shail-mehta marked this pull request as ready for review November 26, 2026 16:04
@github-actions

Copy link
Copy Markdown

The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs.

Core Committers: Use this line as a base for the props when committing in SVN:

Props shailu25.

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.


Props Bot commands

You can trigger Props Bot actions by commenting on this PR:

  • @propsbot add <username> to give props to a GitHub or WordPress.org user. Requires write access.
  • @propsbot remove <username> to leave a user out of the props. Requires write access.
  • @propsbot refresh to refresh this list. Adding the props-bot label works too.

@lancewillett lancewillett left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Each archive assertion checks the node already returned by the admin bar. Core removes the ordinary post type before the next test. The archive tests retain their coverage with all three unregister calls removed.

AI review · gpt-6.2-astra

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: In review

Development

Successfully merging this pull request may close these issues.

3 participants